<?php
/*
 * @Author: 李明
 * @Date: 2022-01-03 16:00:44
 * @LastEditTime: 2022-01-03 16:09:38
 * @LastEditors: 李明
 * @Description:
 * @FilePath: /CRM2.0-PHP/app/Http/Resources/product/product.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Resources\Product;

use Illuminate\Http\Resources\Json\JsonResource;

class Product extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $product['name'] = $this->name;
        $product['classify_id'] = $this->class_id;
        $product['classify_name'] = $this->product_class->category_name;
        $product['rate'] = $this->rate;
        $product['money'] = $this->money;
        $product['detail'] = $this->detail;
        $product['content'] = $this->content;
        $product['ceiling'] = $this->ceiling;
        $product['sale_time'] = $this->sale_time;
        $product['commission'] = $this->commission;
        $product['pay_long'] = $this->pay_long;
        $product['long_time'] = $this->long_time;
        $product['results_rate'] = $this->results_rate;
        $product['year_type'] = $this->year_type;
        $product['remark'] = $this->remark;
        $product['create_time'] = date('Y-m-d', strtotime($this->create_time));
        $product['update_time'] = date('Y-m-d', strtotime($this->update_time));
        switch ($this->time_unit) {
            case 1:
                $product['time_unit'] = '日';
                break;
            case 2:
                $product['time_unit'] = '月';
                break;
            case 3:
                $product['time_unit'] = '年';
                break;
            default:
                $product['time_unit'] = '未知';
        }

        switch ($this->commission_type) {
            case 1:
                $product['commission_type'] = '年化业绩';
                break;
            case 2:
                $product['commission_type'] = '合同金额';
                break;
            case 3:
                $product['commission_type'] = '其他';
                break;
            default:
                $product['commission_type'] = '未知';
        }

        switch ($this->pay_type) {
            case 2:
                $product['pay_type'] = '自然月';
                break;
            case 4:
                $product['pay_type'] = '到期付';
                break;
            case 5:
                $product['pay_type'] = '不付款';
                break;
            default:
                $product['pay_type'] = '未知';
        }

        switch ($this->pay_time_unit) {
            case 1:
                $product['pay_time_unit'] = '日';
                break;
            case 2:
                $product['pay_time_unit'] = '月';
                break;
            case 3:
                $product['pay_time_unit'] = '年';
                break;
            default:
                $product['pay_type'] = '未知';
        }
        /*tag 返回的问题我没有处理
        if (isset($product_dic['tag'])) {
            $tag_list = explode(',', $product_dic['tag']);
            if ($tag) {
                if (in_array($tag, $tag_list)) {
                    $products[] = $product_dic;
                }
            } else {
                $products[] = $product_dic;
            }
        } else {
            $products[] = $product_dic;
        }
        */
        return $product;
    }
}
